package com.ilovetolearn.util
{
	import com.ilovetolearn.model.ModelLocator;

	import flash.events.ErrorEvent;
	import flash.events.Event;
	import flash.media.Sound;
	import flash.net.URLRequest;

	public class SoundProc
	{
		private var sound:Sound;
		private var _model:ModelLocator=ModelLocator.getInstance();

		public function SoundProc()
		{
		}

		public function playSound(url:String):void
		{

			try
			{
				/*发布时去掉*/
				url=_model.site + url;
				if (sound != null)
				{
					sound.close();
				}
				if (url != null && url != "")
				{
					var request:URLRequest=new URLRequest(url);
					sound=new Sound();
					sound.addEventListener(Event.COMPLETE, onSoundCompleteHandler); //载入完成事件
					sound.load(request);
				}
			}
			catch (e:ErrorEvent)
			{
				trace(e.toString());
			}
		}

		private function onSoundCompleteHandler(e:Event):void
		{
			sound.play();
			sound=null;
		}
	}
}